package com.wangyadong.hobby.concurrent;

import java.util.Arrays;
import java.util.concurrent.locks.StampedLock;

public class StampLockDemo {
    public static final StampedLock stampedLock = new StampedLock();
    private static volatile int shareData = 0;

    public static void main(String[] args) {
//        for (int i = 0; i < 10; i++) {
//            new Thread(() -> {
//                long stamp = stampedLock.writeLock();
//                shareData+=1;
//                PRINT_CONSUMER.accept("----------------------------" + shareData);
//                stampedLock.unlockWrite(stamp);
//            }).start();
//        }
        Arrays.stream(shellSort(new Integer[]{20, 100, 7, 5, 3, 8, 1})).forEach(System.out::println);

    }

    public static Integer[] insertSort(Integer[] args) {
        int j;
        for (int p = 1; p < args.length; p++) {
            Integer tmp = args[p];
            for (j = p; j > 0 && tmp.compareTo(args[j - 1]) < 0; j--) {
                args[j] = args[j - 1];
            }
            args[j] = tmp;
        }
        System.out.println("----------------------------------");
        return args;
    }

    public static Integer[] shellSort(Integer[] args) {
        int j;
        for (int gap = args.length / 2; gap > 0; gap /= 2) {
            Integer temp = args[gap];
            for (j = gap; j > 0 && temp.compareTo(args[j - gap]) < 0; j -= gap) {
                args[j] = args[j - gap];
            }
            args[j] = temp;
        }
        return args;
    }
}
